package com.seal.yoyoshop.adminweb;

import com.seal.yoyoshop.service.GoodsService;
import com.seal.yoyoshop.service.impl.GoodsServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "GoodsDeleteServlet", value = "/admin/goodsDelete")
public class GoodsDeleteServlet extends HttpServlet {

    private GoodsService goodsService = new GoodsServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String goodsIdstr = request.getParameter("id");
        int goodsId = Integer.parseInt(goodsIdstr);
        String statusstr = request.getParameter("status");
        int status = Integer.parseInt(statusstr);

        boolean isSuccess = goodsService.deleteGoodsById(goodsId);
        if(isSuccess)response.sendRedirect("goodsList?status="+status+"&page=1&size=16");
    }

}
